var sign = {
  point: 0,
  signCount: 0,
  visible: false,
  elm: $('#sign-container'),
  message: $('#message'),
  init: function () {
    this.renderBg()
  },
  getData: function () {
    var data = getPoints()
    if (data.data) {
      this.point = data.data.surplusPoints
      this.signCount = data.data.signCount
    }
  },
  renderBg: function () {
    try {
      var url = page.data.bgs[6].typePicture[0].picPath3
      $('#sign-container').css('background-image', 'url(' + url + ')')
    } catch (error) {
      console.log('dialog render error')
    }
  },
  render: function () {
    var page = Math.floor(this.signCount / 7)
    var html = ''
    // var html = '<div class="title">连续签到<span class="color">' + this.signCount + '</span>天,活跃值：<span class="color">' + this.point + '</span></div>';
    for (var i = page * 7; i < (page + 1) * 7; i++) {
      var className = ''
      if (i < this.signCount) {
        className = 'active'
      }
      html += '<div id="sign-' + (i % 7) + '" class="sign-item ' + className + '"><div class="time">第' + (i + 1) + '天</div></div>'
    }
    $('#sign-body').html(html)
  },
  /**
   * parames: {points, desc}
   */
  signPoints: function (parames) {
    var data = signPoints(parames)
    var _this = this
    var msg = ''
    if (data.code == 200) {
      msg = '签到成功！'
    } else {
      msg = data.msg || '已签到，明天继续签到！'
    }
    _this.getData()
    _this.render()
    _this.message.html(msg).fadeIn()
    setTimeout(function () {
      _this.message.fadeOut().html('')
    }, 2 * 1000)
  },
  show: function () {
    this.visible = true
    this.elm.fadeIn()
  },
  hide: function () {
    this.visible = false
    this.elm.fadeOut()
  }
}